<?php
/**
 * 品牌管理控制器 
 */
class BreedAction extends CommonAction{
    public function index(){
        $result=M('breed')->select();
        $this->data=$result;
        $this->display();
    }
    public function addShow(){
        $this->display();
    }
    public function add(){
        $data=array(
            'name'=>$this->_post('name'),
            'breed_logo'=>$this->_post('logo')
        );
        if(M('breed')->data($data)->add()){
            $this->success('添加品牌成功',U('index'));
        }else{
            $this->error('添加品牌失败');
        }
    }
 public function editShow(){
        $bid=(int)$_GET['bid'];
        $result=M('breed')->where(array('bid'=>$bid))->find();
        $this->data=$result;
        $this->display();
    }
    public function edit(){
        $data=array(
            'bid'=>(int)$_POST['bid'],
            'name'=>$this->_post('name'),
            'breed_logo'=>$this->_post('logo')
        );
        if(M('breed')->data($data)->save()){
            $this->success('修改品牌成功',U('index'));
        }else{
            $this->error('修改品牌失败');
        }
    }
    
    public function up(){
        import('ORG.Net.UploadFile');

        $upload = new UploadFile();// 实例化上传类 
        $upload->maxSize  = 3145728 ;// 讴置附件上传大小 
        $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 讴置附件上传类型 
        $upload->savePath =  './uploads/breed/';// 讴置附件上传目录 
        $upload->saveRule=time().uniqid();
        if(!$upload->upload()) {// 上传错诣 提示错诣信息 
            $this->error($upload->getErrorMsg()); 
        }else{// 上传成功 获叏上传文件信息 
            return $upload->getUploadFileInfo(); 
        }
    }
}

?>
